/**
 * 
 */
package com.yidin.entry;

import java.util.List;

import com.yidin.lsc.Coupon.CouponItem;
import com.yidin.lsc.R;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

/**
 * 优惠券图片列表
 * 
 * @author cola
 * 
 */
public class CouponAdapter extends BaseAdapter {
	private Context mContext;
	private List<CouponItem> filterArray;

	public CouponAdapter(Context mContext, List<CouponItem> filterArray) {
		this.mContext = mContext;
		this.filterArray = filterArray;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.filterArray.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return this.filterArray.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
//		int width = 450;// bmImg.getWidth();
//		int height = 250;// bmImg.getHeight();
		// bmImg.recycle();
		LinearLayout ll = new LinearLayout(mContext);
		ll.setGravity(0x01);
//		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);  
//		lp.setMargins(2, 2, 2, 2); 
//		ll.setLayoutParams(lp);
		ImageView imageview = new ImageView(mContext);

		imageview.setLayoutParams(new ListView.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		imageview.setImageBitmap(BitmapFactory.decodeResource(
				mContext.getResources(), R.drawable.photo));
		// ((Gallery) convertView).setGravity(Gravity.CENTER);
		imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);// 设置显示比例类型
		ll.addView(imageview);
		return ll;
	}

}
